"""
   ┌─┐       ┌─┐ + +
┌──┘ ┴───────┘ ┴──┐++
│                 │
│       ───       │++ + + +
███████───███████ │+
│                 │+
│       ─┴─       │
│                 │
└───┐         ┌───┘
    │         │
    │         │   + +
    │         │
    │         └──────────────┐
    │                        │
    │                        ├─┐
    │                        ┌─┘
    │                        │
    └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
      │ ─┤ ─┤       │ ─┤ ─┤
      └──┴──┘       └──┴──┘  + + + +
             神兽保佑
            代码无BUG!
"""
import pymysql

from operating_sql import SQLManager
import pandas as pd


class ExcelToSql:
    def __init__(self):
        self.sql = SQLManager()

    def read_file(self):
        """
                :return: 返回所有Excel表中的数据
                """
        xlxs_data = []
        file_data = pd.read_excel("./new_weibo_1.xlsx")
        for data in file_data.values:
            xlxs_data.append(data)
        print(len(xlxs_data))
        return xlxs_data

    def ins_sql(self):
        xlxs_data = self.read_file()
        for data in xlxs_data:
            ins_sql = 'insert into weibo(img_id,content,user_tags,tags,img_number) values ("%s","%s","%s","%s","%s")' % (
                data[0], pymysql.escape_string(data[1]), data[3], data[2], data[4])
            self.sql.run(ins_sql)
            print(data)

    def run(self):
        self.ins_sql()


if __name__ == '__main__':
    ets = ExcelToSql()
    ets.run()
